#include"BlockQueue.hpp"
using namespace std;
using namespace my_blockqueue;

void* consumer(void* args)
{
    BlockQueue<int>* bq = (BlockQueue<int>*)args;
    while(true)
    {
        sleep(1);
        int data = 0;
        bq->Pop(&data);
        cout << "消费者消费了一个数据" << data << endl;
    }
}

void* producter(void* args)
{
    BlockQueue<int>* bq = (BlockQueue<int>*)args;
    while(true)
    {
        // sleep(1);
        int data = rand()%20 + 1;
        bq->Push(data);
        cout << "生产者生产了一个数据" << data << endl;
    }
}

int main()
{
    // std::cout << "hello world" << std::endl;
    BlockQueue<int>* bq = new BlockQueue<int>();

    pthread_t c, p;
    pthread_create(&c, nullptr, consumer, (void*)bq);
    pthread_create(&p, nullptr, producter, (void*)bq);

    pthread_join(c, nullptr);
    pthread_join(p, nullptr);

    return 0;
}